package com.xpalive.base.valid;

import com.xpalive.base.valid.adapter.ComparableSeqValidator;
import java.lang.annotation.Documented;
import java.lang.annotation.ElementType;
import java.lang.annotation.Repeatable;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
import javax.validation.Constraint;
import javax.validation.Payload;

/*
 *  @ComparableSeqValid.Sequence(value = 1,group = "1")
 *  private LocalDate start;
 *
 *  @ComparableSeqValid.Sequence(value = 2,group = "1")
 *  private LocalDate stop;
 *
 *  @ComparableSeqValid.Sequence(value = 2,group = "2")
 *  private LocalDate begin;
 *
 *  @ComparableSeqValid.Sequence(value = 4,group = "2")
 *  @NotNull
 *  private LocalDate end;
 */

@Target({ElementType.TYPE})
@Retention(RetentionPolicy.RUNTIME)
@Constraint(validatedBy = ComparableSeqValidator.class)
@Documented
public @interface ComparableSeqValid {

    String message() default "开始值必须小于结束值";

    Class<?>[] groups() default {};

    Class<? extends Payload>[] payload() default {};


    @Target({ElementType.FIELD, ElementType.METHOD})
    @Retention(RetentionPolicy.RUNTIME)
    @Documented
    @Repeatable(value = Sequences.class)
    @interface Sequence {

        int value();

        //分组
        String group() default "";

        //是否包含前值
        boolean equalPre() default true;
    }

    @Target({ElementType.FIELD, ElementType.METHOD})
    @Retention(RetentionPolicy.RUNTIME)
    @Documented
    @interface Sequences {

        Sequence[] value();
    }
}
